<!-- user表单弹窗 -->
<form id="card-form" lay-filter="card-form"
	class="layui-form model-form">
	<input name="id" type="hidden" />
	<input name="cardCode"  type="hidden"/>
	<input name="createId"  type="hidden"/>
	
	<div class="layui-form-item">
		<label class="layui-form-label">名称</label>
		<div class="layui-input-block">
			<input name="cardName" placeholder="请输入卡片名称" type="text"
				   class="layui-input" lay-verify="required" />
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">服务名称</label>
		<div class="layui-input-block">
			<input name="serviceName" placeholder="请输入服务名称" type="text"
				   class="layui-input" lay-verify="required" />
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">次数</label>
		<div class="layui-input-block">
			<input name="serviceTimes" placeholder="请输入使用次数" type="text"
				class="layui-input" lay-verify="required|number" required />
		</div>
	</div>
	
	<div class="layui-form-item">
			<label class="layui-form-label">状态</label>
		<div class="layui-input-block">
			<input type="radio" name="isActive" value="1" title="有效" checked/>
			<input type="radio" name="isActive" value="0" title="无效"/>
		</div>
	</div>

	<div class="layui-form-item model-form-footer">
		<button class="layui-btn layui-btn-primary" type="button"
			ew-event="closeDialog">取消</button>
		<button class="layui-btn" lay-filter="form-submit" lay-submit>保存</button>
	</div>
</form>
<script>
	layui.use([ 'layer', 'admin', 'form', 'formSelects', 'upload' ],
					function() {
						var $ = layui.jquery;
						var layer = layui.layer;
						var admin = layui.admin;
						var form = layui.form;
						var upload = layui.upload;
						var formSelects = layui.formSelects;

						form.render('radio');
						form.render('select');

						var url = 'system/card/add';
						// 回显user数据
						var card = admin.getTempData('t_card');
						if (card) {
							$('input[name="id"]').attr('readonly',
									'readonly');
							url = 'system/card/update';
							$("input[name=isActive][value=0]").attr("checked", card.isActive == 0 ? true : false);
			                $("input[name=isActive][value=1]").attr("checked", card.isActive == 1 ? true : false);
							form.val('card-form', card);
						}

						// 表单提交事件
						form.on('submit(form-submit)', function(data) {
							layer.load(2);
							admin.req(url, data.field, function(data) {
								layer.closeAll('loading');
								if (data.code == 1) {
									layer.msg(data.msg, {
										icon : 1
									});
									admin.finishPopupCenter();
								} else {
									layer.msg(data.msg, {
										icon : 2
									});
								}
							}, "post");
							return false;
						});
					});
</script>